Attribute VB_Name = "modODBCFlextronics"
'---------------------------------------------------------------------------------------
'Module     : modODBC
'Date       : 05/18/2004
'Updated    : 02/21/2005
'Author     : Chris Elwell
'Purpose    : This is an example of a CIC integration module. This is for demostration
'           purposes only. You must write the code required to get/writeback data from/to
'           your customer's data source.
'
'           This example uses the FSMSClientTest.mdb. A DSN is setup as FSMSClientTest.
'           Regardless of the integration method, CICs must have a module that contains
'           specific sub routines. All of these subs/functions listed below must exist
'           as they are called from the main program.
'           Public Function GetData(ByVal strKey As String) As Boolean - this routine is
'               called when the Order ID field loses focus. This is where you would code to
'               get order data from a customer and populate the screen fields. You can create
'               and call as many support routines as necessary. Also, this routine should
'               return a boolean True if getting the order data was succesful and a boolean
'               False if it was not.
'           Public Sub WriteReply() - this is called after a successful shipment. A typical
'               use would be to write FXRS reply data back to a customer's system, but can be
'               used for anything that you want to have happen after a pckage is shipped.
'           Public Sub WriteError() - this is called after an error is returned from FXRS.
'           Public Sub WriteDelete(ByVal strTracking As String) - this is called after a
'               package is successfully deleted.
'           Public Sub AfterClose() - this is called after FXRS is closed.
'           Public Sub BeforeClose() - this is called just before an FXRS close transaction
'               is sent.
'Updated:   Public Function BeforeShip() - Return TRUE to continue shipment, False to cancel.
'           Public Sub Initialize() - this is called once on program execution.
'           Public Sub BeforeBatch() - this is called before processing a batch file.
'           Public Sub BeforeBatchShip() - this is called before each individual batch transaction.
'New:       Public Sub AfterAddrLookup() - this is called after cboCustID, cboContact, and cboCompany lose focus
'New:       Public Sub AfterDeptLostFocus() - this is called after cboDept or f38 loses focus.
'
' 2005-04-20, JFW, Added AddDSN for integration database.
' 2006-11-07, JFW, Add order to MPS select to preserve package order
' 2007-04-13, JFW, Allow for custom screen display, AfterConnect
'
'---------------------------------------------------------------------------------------


Option Explicit

#If Flextronics Then

Dim m_objFSO As FileSystemObject
Dim m_colFiles As Collection
Dim m_colKeys As Collection
Dim m_colInput As Collection
Dim m_strHeader() As String
Public m_strFilePath As String
Public m_strKey As String

''2/8/05 - API function declaration to add DSN to system used in AddDSN() function.
'Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal _
'   hwndParent As Long, ByVal fRequest As Long, ByVal _
'   lpszDriver As String, ByVal lpszAttributes As String) As Long

'+
' 2006-09-20, JFW, From Copernicus FXI
' Declare object(s)
Public g_strCustNo As String        'Hold Customer Number
Public g_strPONo As String          'Hold Customer PO Number
Public g_strRefNo As String         'Hold Customer Reference Number
Public g_strCountry As String       'Hold shipto Country
Public g_strZip As String           'Holds zip code
Public g_strEmail As String         'Hold Email address
Public g_strEmail2 As String        'Hold Email address
Public g_blnServiceOrder As Boolean 'Flage for email
'~

   
'---------------------------------------------------------------------------------------
' Procedure : AddDSN
' DateTime  : 2/8/2005
' Purpose   : Adds the FSMSClient v720.3 DSN
' Call from : Form_Load
'---------------------------------------------------------------------------------------
'
Private Function AddDSN() As Boolean
    On Error GoTo EH
    
    Dim ret As Long
    Dim Driver As String
    Dim Attributes As String
    
'    If GetSystemName = "CAN-00278478" Then
'        Driver = "Microsoft Access Driver (*.mdb)"
'        Attributes = Attributes & "DBQ=C:\Program Files\FedEx\Integration\Projects\Copernicus\Data\Orders.mdb" & Chr(0)
'    Else
'        Driver = "Microsoft Access Driver (*.mdb)"
'        Attributes = Attributes & "DBQ=" & App.Path & "\FSMSClientTest.mdb" & Chr(0)
'    End If
'    Attributes = Attributes & "DSN=CopernicusFSMS" & Chr(0)
'    Attributes = Attributes & "DESCRIPTION=FSMS Client Copernicus ship data" & Chr(0)
'
'    ret = SQLConfigDataSource(0, 4, Driver, Attributes)
   
    If ret <> 1 Then
        AddDSN = False
    Else
        AddDSN = True
    End If

    Exit Function
EH:
    AddDSN = False

End Function
'


' 2011-02-01, JFW, Clear DG disclaimer automatically.
Public Function AfterDGDisclaimer() As Boolean
    If GetSystemName = "WINXPC9CA96EA3" Then
        AfterDGDisclaimer = True
    Else
        AfterDGDisclaimer = False
    End If
End Function

'---------------------------------------------------------------------------------------
' Procedure : BeforeClose()
' DateTime  : 7/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed before
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Function BeforeClose() As Boolean

    BeforeClose = True

End Function
'

Public Function ClearCommodity() As Boolean

End Function
'

Public Function ClearShipScreen() As Boolean

    frmShip.f38 = g_clsReg.GetRegistryValue("Carry_f38", "")
    frmShip.f1273 = "02"
    
    m_strFilePath = ""
    m_strKey = ""
    
End Function

'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetData(ByVal strKey As String) As Boolean
    On Local Error GoTo Handler
    Dim objTextStream As TextStream
    Dim objfile As File
    Dim strData As String
    Dim strFields() As String
    Dim i As Long
        
    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" _
    And g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Order Lookup" Then
        GetData = True
        Exit Function
    End If
        
    If m_objFSO Is Nothing Then Set m_objFSO = New FileSystemObject
    
    If Not Connect Then Exit Function   'set conection and recordset

    If m_colFiles Is Nothing Then Set m_colFiles = New Collection
    If m_colKeys Is Nothing Then Set m_colKeys = New Collection
        
    ' See if the key is in the cache
    If GetItem(m_colKeys, strKey) = "" Then
        If g_clsSettings.Setting("IntegrationFolderIn") = "" Then
            If GetSystemName = "WINXPC9CA96EA3" Then
                g_clsSettings.Setting("IntegrationFolderIn") = "C:\Projects\FSMSClient\Database\Flextronics\"
                g_clsSettings.SaveSettings
            Else
                Err.Raise 12345, "ODBCFlextronics", "Import folder required, see configuration XML, IntegrationFolderIn"
            End If
        End If
        'IntegrationFolderIn
        If Not MainFSO.FolderExists(g_clsSettings.Setting("IntegrationFolderIn")) Then
            Err.Raise 12345, "ODBCFlextronics", "Import folder doesn't exist, see configuration XML, IntegrationFolderIn"
        End If
        ' If not in cache, examine all files
        For Each objfile In m_objFSO.GetFolder(g_clsSettings.Setting("IntegrationFolderIn")).Files
            If LCase(Left(objfile.name, 1)) = "s" Then
            If LCase(Right(objfile.name, 4)) = ".txt" Then
            If GetItem(m_colFiles, objfile.name) = "" Then
                Set objTextStream = objfile.OpenAsTextStream(ForReading)
                    
                Do While Not objTextStream.AtEndOfStream
                    strData = objTextStream.ReadLine
                    If strData <> "" Then
                        strFields = Split(strData, "|")
                        If LBound(strFields) = 0 _
                        And UBound(strFields) > 0 Then
                            If UCase(strFields(0)) <> "SHIPMENT CODE" Then
                                If GetItem(m_colKeys, strFields(0)) <> "" Then
                                    m_colKeys.Remove strFields(0)
                                End If
                                m_colKeys.Add objfile.name, strFields(0)
                                If GetItem(m_colFiles, objfile.name) <> "" Then
                                    m_colFiles.Remove objfile.name
                                End If
                                m_colFiles.Add objfile.Path, objfile.name
                            End If ' header
                        End If ' array
                    End If ' strData
                Loop
            
            End If ' not in file collection
            End If ' txt file
            End If ' "Ship" file
        Next objfile
    End If ' key not in cache
    
    Set m_colInput = New Collection

    If GetItem(m_colKeys, strKey) <> "" Then
        m_strFilePath = m_colFiles.item(m_colKeys.item(strKey))
        m_strKey = strKey
        If m_objFSO.FileExists(m_strFilePath) Then
            Set objTextStream = m_objFSO.OpenTextFile(m_strFilePath)
                    
            Do While Not objTextStream.AtEndOfStream
                strData = objTextStream.ReadLine
                If strData <> "" Then
                    
                    strFields = Split(strData, "|")
                    
                    If LBound(strFields) = 0 _
                    And UBound(strFields) > 0 Then
                        If UCase(strFields(0)) = "SHIPMENT CODE" Then
                            m_strHeader = Split(strData, "|")
                        Else
                            If LBound(m_strHeader) <> LBound(strFields) _
                            Or UBound(m_strHeader) <> UBound(strFields) Then
                                Err.Raise 12345, "ODBC.GetData", "Data items and column heading does not match; " _
                                    & "Input key " & strKey & "; " _
                                    & "line " & CStr(m_colInput.Count + 1) & ".  "
                            End If
                            If UCase(strFields(0)) = UCase(strKey) Then
                                m_colInput.Add strFields
                                Exit Do
                            End If
                        End If ' header
                    End If ' bounds
                End If ' strDate
            Loop
    
            Call DeleteIntlCommodities(strKey)
    
            Call GetDataToShip
    
        Else
            Set g_frmMsgBox = New frmMsgBox
            g_frmMsgBox.Message = "Input file not found for key " & strKey & ".  "
            g_frmMsgBox.TimeOut = 4000
            Set g_frmMsgBox = Nothing
            m_colKeys.Remove strKey
        
        End If
    
    Else
        Set g_frmMsgBox = New frmMsgBox
        g_frmMsgBox.Message = "Input file not found for key " & strKey & ".  "
        g_frmMsgBox.TimeOut = 4000
        Set g_frmMsgBox = Nothing
    End If
    GetData = True
Release:
    ' call kill
    Exit Function
Handler:
    MsgBox Err.Description, , "modODBC.GetData"
    On Error Resume Next
    m_colFiles.Remove m_colKeys(strKey)
    m_colKeys.Remove strKey
    Call Kill
    Resume Release
    

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : GetData()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Called from frmShip.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Sub GetDataToShip()

    On Local Error GoTo Handler

    Dim i As Long
    Dim varData As Variant
    
    With frmShip
        
        varData = m_colInput(1)
            
        For i = LBound(m_strHeader) To UBound(m_strHeader)
            Select Case UCase(m_strHeader(i))
            Case "SHIPMENT CODE"
                ' 2008-02-16, From Meena
                ' 2008-03-20, Back to po
                .f3056.Text = varData(i)
                .f1.Text = varData(i)
                g_str1 = varData(i)
            Case "NOTE", "CARRIER"
            Case "CUSTOMER NAME"
                .f12.Text = varData(i)
            Case "ATTENTION"
                .f11.Text = varData(i)
            Case "STREET ADDRESS", "ADDRESS LINE1"
                .f13.Text = varData(i)
            Case "SUITE", "ADDRESS LINE2"
                .f14.Text = varData(i)
            Case "CITY"
                .f15.Text = varData(i)
            Case "STATE"
                .f16.Text = varData(i)
            Case "POSTAL CODE"
                .f17.Text = varData(i)
            Case "COUNTRY"
                .f50.Text = varData(i)
            Case "TELEPHONE"
                .f18.Text = varData(i)
            Case "REFERENCE", "REFERENCE1"
                ' 2008-02-16, From Meena, 2008-03-20, Back
                .f25.Text = varData(i)
            Case "WEIGHT"
                .f1670.Text = varData(i)
            Case "PAYMENT"
            Case "SERVICE"
                .f1274 = "01"
                .f1273 = "02"
            Case "IN/AUTO/QUERY/"
            Case "SHIPMENT"
            Case "9AM Service"
                If varData(i) = "Y" Then
                    .f1274.Text = "06"
                End If
            Case "RETURN SHIPMENT"

'WEIGHT|PAYMENT|SERVICE|IN/AUTO/QUERY/|SHIPMENT|9AM Service|RETURN SHIPMENT
'0.5|P|A|I|S|N|N

            End Select
        Next i
        
        .f116.Text = 1
        ' .f1670.SetFocus 'Set focus to read scale
        
        If .f50 = "" Then
            If IsNumeric(.f17.Text) Then
                .f50.Text = "US"
            Else
                .f50.Text = "CA"
            End If
        End If
        
    End With


    g_strErrorLocation = "Done"
Release:
    ' call kill
    Exit Sub
Handler:
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , "modODBC.GetDataToShip"
    Call Kill
    Resume Release
    Resume

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : GetPickupData()
' DateTime  : 1/30/2006
' Purpose   : REQUIRED SUB. Called from frmAddTags.f1_LostFocus, which is the OrderID field.
'             Call routines needed to get data from the customer's system and assign the
'             value to the appropriate fields on the Ship form. This example uses ODBC.
'---------------------------------------------------------------------------------------
'
Public Function GetPickupData(ByVal strKey As String) As Boolean


    GetPickupData = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : WriteBatchEditReply()
' DateTime  : 1/17/2006
' Purpose   : REQUIRED SUB. Called after a successful Batch Error Edit transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBatchEditReply()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteBOLReply()
' DateTime  : 1/11/2006
' Purpose   : REQUIRED SUB. Called after a successful FedEx Freight BOL transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteBOLReply()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteReply()
' DateTime  : 2/14/2005
' Purpose   : REQUIRED SUB. Called after a successful ship transaction.
'             This example shows how to obtain multiple occurrence fields from the
'             FXRS reply and how to obtain multiple occurrence fields included in the
'             input transaction but not returned in the FXRS reply.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReply()
    
    On Local Error GoTo Handler
    
    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" _
    And g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Order Lookup" Then
        Exit Sub
    End If
    
    If m_objFSO Is Nothing Then Set m_objFSO = New FileSystemObject
    
    If Not Connect Then Exit Sub   'set conection and recordset
    
'    If m_strFilePath <> "" Then
'        If m_objFSO.FileExists(m_strFilePath) Then
'        If m_objFSO.FolderExists(g_clsSettings.Setting("IntegrationFolderIn")) Then
'
'            If Not m_objFSO.FolderExists(g_clsSettings.Setting("IntegrationFolderIn") & "Done") Then
'                m_objFSO.CreateFolder (g_clsSettings.Setting("IntegrationFolderIn") & "Done")
'            End If
'
'            With m_objFSO.GetFile(m_strFilePath)
'                If m_objFSO.FileExists(g_clsSettings.Setting("IntegrationFolderIn") & "Done\" & .name) Then
'                    m_objFSO.DeleteFile g_clsSettings.Setting("IntegrationFolderIn") & "Done\" & .name, True
'                End If
'                .Move g_clsSettings.Setting("IntegrationFolderIn") & "Done\"
'            End With
'        End If
'        End If
'    End If
'
'    If GetItem(m_colKeys, m_strKey) <> "" Then
'        If GetItem(m_colFiles, m_colKeys.item(m_strKey)) <> "" Then
'            m_colFiles.Remove m_colKeys.item(m_strKey)
'        End If
'        m_colKeys.Remove m_strKey
'    End If
    
    m_strFilePath = ""
    m_strKey = ""
        
    g_strErrorLocation = "Done"
    
Release:
    ' call kill
'    If rsMPS.State = adStateOpen Then rsMPS.Close
'    Set rsMPS = Nothing
    Exit Sub

Handler:
    MsgBox "Error at " & g_strErrorLocation & " - " & Err.Description, , "modODBC.WriteReply"
    Call Kill
    Resume Release
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteError()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an FXRS Error reply transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteError()
    MsgBox "Shipping Error: " & g_str3, vbCritical, "FSMS Error"
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteDelete()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             successful FXRS Delete.
'---------------------------------------------------------------------------------------
'
Public Sub WriteDelete(ByVal strTracking As String)
'Called:    frmShip Parsecomplete event on FSMS 123 reply
'Purpose:   update customer table on void
    On Local Error GoTo Handler
    
'    ' Declare variables for procedure
'    Dim strSQL As String
'    Dim lngErr As Long
'
'    If g_clsReg.GetRegistryValue("IntegrationLevel", "Writeback") <> "Writeback" Then
'        Exit Sub
'    End If
'
'    ' Validate Connection state
'    If Not Connect Then Exit Sub
'
'    ' Validate * is compliant with inline error handling
'    On Error Resume Next
'
'    ' Set SQL statement
'    strSQL = "Delete From `FedEx Write back`"
'    strSQL = strSQL & " Where `Tracking #` = '" & strTracking & "'"
'
'    'Execute SQL statement
'    m_CNOut.Execute strSQL
'
'    lngErr = Err.number
'    Err.Clear
'
'    If lngErr <> 0 Then
'        strSQL = "Delete From `FedEx Write back`"
'        strSQL = strSQL & " Where `Tracking #` = '" & strTracking & "'"
'
'        'Execute SQL statement
'        m_CNOut.Execute strSQL
'    End If
    
Release:
   ' call kill
   Exit Sub
Handler:
    MsgBox Err.Description, , "modODBC.WriteDelete"
    Call Kill
    Resume Release
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteReturnDelete()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label delete transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnDelete(ByVal strTracking As String)

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteReturnReply()
' DateTime  : 7/14/2005
' Purpose   : REQUIRED SUB. Called after a successful return label transaction.
'             This is called for both regular and online return labels.
'---------------------------------------------------------------------------------------
'
Public Sub WriteReturnReply()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteTagReply()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : WriteCancelTagReply()
' DateTime  : 1/26/2006
' Purpose   : REQUIRED SUB. Called after a successful Cancel Call Tag/Express Tag transaction.
'---------------------------------------------------------------------------------------
'
Public Sub WriteCancelTagReply()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : Connect()
' DateTime  : 7/5/2004
' Purpose   : Open connection to ODBC test DSN. Instantiate module level recordset.
'---------------------------------------------------------------------------------------
'
Private Function Connect() As Boolean
    On Local Error GoTo Handler
    Dim strDSN As String
    Dim boolSecondTry As Boolean
    
    Connect = True
    
    Exit Function

Handler:
    If Not boolSecondTry Then
        boolSecondTry = True
        If Err.number = -2147467259 Then
            Call AddDSN
            Resume
        End If
    End If
    MsgBox Err.Description, , "modODBC.Connect"
    Call Kill        'kill connection and recordset

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : Kill()
' DateTime  : 7/5/2004
' Purpose   : Close connection and recordset objects and set = to nothing.
'---------------------------------------------------------------------------------------
'
Public Sub Kill()
    On Local Error GoTo Handler
    
    Exit Sub
Handler:
    MsgBox Err.Description, , "modODBC.Kill"

End Sub
'

' 2011-05-05, JFW, For Scapa
Public Function TDAutoCloseEnabled() As Boolean
    TDAutoCloseEnabled = False
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerify()
' DateTime  : 5/12/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             Address Verification. Three possible status codes are passed. See comments
'             below.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerify(ByVal intStatusCode As Integer)

    Select Case intStatusCode
        'Address is verfified
        Case 1

        'Soft error
        Case 2

        'Hard error
        Case 3

    End Select

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterAddrVerifyUpdate()
' DateTime  : 9/13/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             an address has been updated on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrVerifyUpdate()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterBatch()
' DateTime  : 4/6/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a batch shipment has been completed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatch()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterBatchShip()
' DateTime  : 10/28/2005
' Purpose   : REQUIRED SUB. Called just after a batch transaction has been processed.
'---------------------------------------------------------------------------------------
'
Public Sub AfterBatchShip()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterClose()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             FXRS Close.
'---------------------------------------------------------------------------------------
'
Public Sub AfterClose()

End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterConnect()

    'Call frmShip.ToggleLookup(True)
    frmShip.f70.ListIndex = 0
    frmShip.f72.ListIndex = 0
    
End Sub
'

' 2007-04-13, JFW, Allow for custom screen display.
Public Sub AfterDisconnect()

    On Error Resume Next
    
End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterLocationChange()
' DateTime  : 3/06/2006
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             the shipping Location has been changed on the Ship form.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLocationChange()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterLoadServices()
' DateTime  : 5/17/2011
' Purpose   : Remove or add custom services.
' 2011-05-17, JFW, New for Scapa
'---------------------------------------------------------------------------------------
'
Public Sub AfterLoadServices(c1 As ComboBox)

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterLostFocus(c1 As Control)

    If c1.name = "f38" Then
        'g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ
    End If
    If c1.name = "f1273" Then
        'g_clsReg.SetRegistryValue "Carry_f1273", Left(frmShip.f1273.Text, 2), REG_SZ
    End If

End Sub
'

'----------------------------------------------------------------------
' Procedure : AfterRateQuote()
' DateTime  : 20071106-01
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             a rate quote.
'---------------------------------------------------------------------------------------
'
Public Sub AfterRateQuote()

End Sub
'

' 2012-01-19, JFW, New for UCS.
Public Function AfterScreenChange(f As Form) As Boolean

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeBatch()
' DateTime  : 20070621-01 Changed BeforeBatch to return a boolean
' Purpose   : REQUIRED SUB. Called before an entire batch is processed.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatch() As Boolean

    BeforeBatch = True

End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeBatchShip()
' DateTime  : 20070822-02 Modified BeforeBatchShip to return a Boolean.
' Purpose   : REQUIRED SUB. Called just before a batch transaction is sent to the server.
'---------------------------------------------------------------------------------------
'
Public Function BeforeBatchShip() As Boolean

    BeforeBatchShip = True

End Function
'

' 2012-01-19, JFW, New for UCS.
Public Function BeforeGotFocus(f As Form, c As Control) As Boolean
    On Error GoTo Test
    Exit Function
Test:
    DebugPrint "BeforeGotFocus, " & Err.Description
    
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BeforeShip()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED Function. Modified to Return Boolean which controls whether or not
'             the shipment will continue or be canceled. Return True to continue shipment,
'             False to cancel.
'---------------------------------------------------------------------------------------
'
Public Function BeforeShip(Optional TransString As String = "") As Boolean
    
    If TransString <> "" Then
        TransactionStripTag TransString, "583"
        TransactionBuilder TransString, "583", g_str1670
        TransString = Replace(TransString, "99,""""", "")
        TransactionBuilder TransString, 99, ""
    End If
    
    DebugPrint "BeforeShip", TransString
    
    ' 2008-01-13, JFW, Tracking number on doc tab requires pre-assignment
    
    If g_str1 = "" Then g_str1 = frmShip.cboCustID.Text
    If Not IsNumeric(g_str116) Then g_str116 = 1
    
    If g_str1274 = "92" Or g_str1274 = "90" Then
        Call frmPreAssign.MakePreAssign(g_str1, CLng(g_str116), "ground")
    Else
        Call frmPreAssign.MakePreAssign(g_str1, CLng(g_str116), "express")
    End If
    
    BeforeShip = True

    '    If frmShip.f25 = "" Then
    '        MsgBox "Reference is mandatory.", vbApplicationModal + vbSystemModal
    '        frmShip.SSTab1.Tab = 0
    '        frmShip.f25.SetFocus
    '        BeforeShip = False
    '    End If
    '
    '    If frmShip.f38 = "" Then
    '        MsgBox "Department is mandatory.", vbApplicationModal + vbSystemModal
    '        frmShip.SSTab1.Tab = 0
    '        frmShip.f38.SetFocus
    '        BeforeShip = False
    '    End If
    
End Function
'


Public Function BeforeShipTrans(ByRef TransString As String) As Boolean

    DebugPrint "BeforeShipTrans, " & TransString
    
    TransString = Replace(TransString, "99,""""", "")
    
    TransactionBuilder TransString, 1621, g_str1222
    TransactionBuilder TransString, 1959, "Tracking number:"
    
    If g_str50 = "CA" Then
        If g_str1274 = "01" Then
            If g_str187 = "188" Or g_str187 = "288" Or g_str187 = "388" Or g_str187 = "488" Then
                ' Zebra ZPL
                TransString = TransString & ""
                TransString = TransString & "2429-1,""01""2430-1,""10""2431-1,""20""2437-1,""50""2438-1,""300""2429-2,""01""2430-2,""750""2431-2,""20""2437-2,""790""2438-2,""300""2429-3,""03""2430-3,""95""2431-3,""25""2432-3,""Attention FedEx Courier /""2433-3,""""2434-3,""1""2429-4,""03""2430-4,""475""2431-4,""25"""
                TransString = TransString & "2432-4,""messager FedEx:""2433-4,""""2434-4,""1""2429-5,""03""2430-5,""230""2431-5,""70""2432-5,""SIGNATURE REQUIRED""2433-5,""""2434-5,""8""2429-6,""03""2430-6,""180""2431-6,""95"""
                TransString = TransString & "2432-6,""This package cannot be released""2433-6,""""2434-6,""1""2429-7,""03""2430-7,""190""2431-7,""120""2432-7,""without obtaining a signature.""2433-7,""""2434-7,""1""2429-8,""03""2430-8,""220""2431-8,""155""2432-8,""NO INDIRECT DELIVERY""2433-8,""""2434-8,""8"""
                TransString = TransString & "2429-9,""03""2430-9,""200""2431-9,""200""2432-9,""SIGNATURE OBLIGATOIRE""2433-9,""""2434-9,""8""2429-10,""03""2430-10,""70""2431-10,""225""2432-10,""Cet envoi ne peut etre laisse sans"""
                TransString = TransString & "2433-10,""""2434-10,""1""2429-11,""03""2430-11,""555""2431-11,""225""2432-11,""signature.""2433-11,""""2434-11,""1""2429-12,""03""2430-12,""180""2431-12,""260""2432-12,""PAS DE LIVRAISON INDIRECTE""2433-12,""""2434-12,""8"""
            ElseIf g_str187 = "199" Or g_str187 = "299" Or g_str187 = "399" Or g_str187 = "499" Then
                ' Eltron EPL
                TransString = TransString & ""
                TransString = TransString & "2429-1,""01""2430-1,""10""2431-1,""20""2437-1,""50""2438-1,""300""2429-2,""01""2430-2,""750""2431-2,""20""2437-2,""790""2438-2,""300""2429-3,""03""2430-3,""85""2431-3,""25""2432-3,""Attention FedEx Courier /""2433-3,""""2434-3,""4""2429-4,""03""2430-4,""495""2431-4,""25"""
                TransString = TransString & "2432-4,""messager FedEx:""2433-4,""""2434-4,""4""2429-5,""03""2430-5,""230""2431-5,""70""2432-5,""SIGNATURE REQUIRED""2433-5,""""2434-5,""8""2429-6,""03""2430-6,""170""2431-6,""95"""
                TransString = TransString & "2432-6,""This package cannot be released""2433-6,""""2434-6,""4""2429-7,""03""2430-7,""185""2431-7,""120""2432-7,""without obtaining a signature.""2433-7,""""2434-7,""4""2429-8,""03""2430-8,""220""2431-8,""155""2432-8,""NO INDIRECT DELIVERY""2433-8,""""2434-8,""8"""
                TransString = TransString & "2429-9,""03""2430-9,""200""2431-9,""200""2432-9,""SIGNATURE OBLIGATOIRE""2433-9,""""2434-9,""8""2429-10,""03""2430-10,""50""2431-10,""225""2432-10,""Cet envoi ne peut etre laisse sans"""
                TransString = TransString & "2433-10,""""2434-10,""4""2429-11,""03""2430-11,""605""2431-11,""225""2432-11,""signature.""2433-11,""""2434-11,""4""2429-12,""03""2430-12,""170""2431-12,""260""2432-12,""PAS DE LIVRAISON INDIRECTE""2433-12,""""2434-12,""8"""
            End If
        End If
    End If
    
    TransString = TransString & "99,"""""
    
    BeforeShipTrans = True
    
End Function
'

'---------------------------------------------------------------------------------------
' Procedure : BuildCustomSPLabel()
' DateTime  : 20070620-04
' Purpose   : REQUIRED SUB. Can be used as hook to create custom EPL or ZPL buffer labels
'             for SmartPost.
'---------------------------------------------------------------------------------------
'
Public Function BuildCustomSPLabel(ByVal strLabel As String) As String

    BuildCustomSPLabel = strLabel

End Function
'

Public Sub EditBoxLostFocus(objControl As Control)

    '    Select Case objControl.name
    '        Case "f18"
    '            If Trim(objControl.Text & "") = "" Then
    '                objControl.Text = "4169265201"
    '            End If
    '    End Select
    
End Sub


'---------------------------------------------------------------------------------------
' Procedure : Initialize()
' DateTime  : 7/5/2004
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed on
'             program execution.
'---------------------------------------------------------------------------------------
'
Public Sub Initialize(Optional f1 As Form)

    frmShip.f38 = g_clsReg.GetRegistryValue("Carry_f38", "")
    frmShip.f1273 = "02"
    ' frmShip.f75.Text = "LBS"
    
    ' Call frmShip.ToggleDepartment(False)
    
    'Call frmShip.ToggleLookup(True)
    
End Sub
'


'---------------------------------------------------------------------------------------
' Procedure : AfterAddrLookup()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboCustID, cboContact, or cboCompany loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterAddrLookup()

End Sub
'

'---------------------------------------------------------------------------------------
' Procedure : AfterDeptLostFocus()
' DateTime  : 2/21/2005
' Purpose   : REQUIRED SUB. Can be used as hook to call routines to be executed after
'             cboDept or f38 loses focus.
'---------------------------------------------------------------------------------------
'
Public Sub AfterDeptLostFocus()

    g_clsReg.SetRegistryValue "Carry_f38", frmShip.f38, REG_SZ
    
End Sub
'

#End If


